#####################################################
# Makefile for Y86 simulation
#####################################################

# Y86 Version can be: seq, seq+, pipe- pipe
# pipe- may fail in most vector, since it is a broken CPU
VERSION		= pipe

########## User should not touch below ############
PATH	    := ../bin:../c_model/misc:$(PATH)
VECLIB		= ../c_model/y86-code
VECTOR		=abs-asum-jmp.yo

TB_PATH	= ./testbench
ifeq ($(VERSION),seq)
TESTBENCH	= $(TB_PATH)/top.v \
			  $(TB_PATH)/seqCheck.v \
			  $(TB_PATH)/hier_seq.v
endif
ifeq ($(VERSION),seq+)
TESTBENCH	= $(TB_PATH)/top.v \
			  $(TB_PATH)/seqCheck.v \
			  $(TB_PATH)/hier_seq.v
endif
ifeq ($(VERSION),pipe-)
TESTBENCH	= $(TB_PATH)/top.v \
			  $(TB_PATH)/pipeCheck.v \
			  $(TB_PATH)/hier_pipe.v
endif
ifeq ($(VERSION),pipe)
TESTBENCH	= $(TB_PATH)/top.v \
			  $(TB_PATH)/pipeCheck.v \
			  $(TB_PATH)/hier_pipe.v
endif

DESIGN		= ../design/$(VERSION)
MODEL		= ../model

nc_opts		= +libext+.v            \
			  +ncinput+dump.tcl 	\
			  +incdir+$(DESIGN) 	\
			  +incdir+$(TB_PATH) 	\
			  -l run_$(VECTOR).log  \
			  $(addprefix -y ,$(MODEL))

run: yo2data getGolden
	ncverilog $(nc_opts) $(TESTBENCH) \
		 $(wildcard $(DESIGN)/*.v)
	mv record.log $(VECTOR).log
	echo "$(VECTOR) result:" > result_$(VECTOR).log
	instrChecker.pl -g golden_$(VECTOR).log -r $(VECTOR).log |tee -a result_$(VECTOR).log
	mv golden_$(VECTOR).log debug/
	mv $(VECTOR).log debug/
	mv run.fsdb debug/
	mv debug/run.fsdb debug/$(VECTOR).fsdb
	mv run_$(VECTOR).log debug/
	mv result_$(VECTOR).log debug/

yo2data:
	yo2data.pl -f $(VECLIB)/$(VECTOR)

getGolden:
	getGolden.pl -v $(VECLIB)/$(VECTOR) -i init.data -o goldenRecord.log
	mv goldenRecord.log golden_$(VECTOR).log

clean:
	-rm *.data
	-rm *.log
	-rm INCA_libs -rf

